package com.dwxt.mall.controller;

import com.dwxt.common.annotation.ValidateFiled;
import com.dwxt.common.annotation.ValidateGroup;
import com.dwxt.common.base.BaseResult;
import com.dwxt.mall.entity.Product;
import com.dwxt.mall.service.ProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/mall/product")
@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    //今日特推，每日特惠

    /**
     * showdoc
     *
     * @param type 必选 string 模块名称(今日特推，每日特惠)
     * @return {"status":200,"msg":"SUCCESS","data":{"total":2,"list":[{"id":3,"name":"羽毛球","price":10.0,"integral":0,"stock":20,"desp":null,"module":"生活商城","categoryId":2,"type":"今日特推","isShelf":1,"createTime":"2020-04-03T17:51:04.000+0000","supplierId":8,"payCategory":1,"version":0,"limitNumber":10,"isLimit":1,"priority":20,"deliveryMethod":"上门自提","coverImgUrl":"http:test","carouselImgUrl":"http:test2"}],"pageNum":10,"pageSize":0,"size":2,"startRow":1,"endRow":2,"pages":0,"prePage":0,"nextPage":0,"isFirstPage":false,"isLastPage":true,"hasPreviousPage":true,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[],"navigateFirstPage":0,"navigateLastPage":0}}
     * @catalog 商城/商品
     * @title 首页由模块查询商品分页
     * @description 首页由模块查询商品分页（今日特推，每日特惠）
     * @url /mall/product/selectProductListByType
     */
    @RequestMapping("/selectProductListByType")
    @ValidateGroup(fileds = {
            @ValidateFiled(index = 0, notNull = true),
    })
    public BaseResult selectProductListByType(String type) {
        //PageHelper.startPage(pageNum, pageSize);
        List<Product> productList = productService.selectProductListByType(type);
        return BaseResult.ok(productList);
    }
    //模块下的日常用品，体育用品

    /**
     * showdoc
     *
     * @param pageNum    必选 string 页码（0开始
     * @param pageSize   必选 int 每页数量
     * @param categoryId 必选 string 商品种类id
     * @param module     必选 string 模块名称(生活商城,活动专区,卡券礼包)
     * @return {"status":200,"msg":"SUCCESS","data":{"total":1,"list":[{"id":2,"name":"篮球","price":100.0,"integral":0,"stock":100,"desp":"圆圆的足球","module":"活动专区","categoryId":1,"type":"0","isShelf":0,"createTime":"2020-04-03T12:14:47.000+0000","supplierId":8,"payCategory":1,"version":0,"limitNumber":0,"isLimit":0,"priority":1,"deliveryMethod":"商家配送","coverImgUrl":"http://demo.com","carouselImgUrl":"http:demo1.com"}],"pageNum":10,"pageSize":0,"size":1,"startRow":1,"endRow":1,"pages":0,"prePage":0,"nextPage":0,"isFirstPage":false,"isLastPage":true,"hasPreviousPage":true,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[],"navigateFirstPage":0,"navigateLastPage":0}}
     * @catalog 商城/商品
     * @title 由模块, 种类查询商品分页
     * @description 由模块, 种类查询商品分页
     * @url /mall/product/selectModuleProductList
     */
    @RequestMapping("/selectModuleProductList")
    @ValidateGroup(fileds = {
            @ValidateFiled(index = 0, notNull = true, filedName = "categoryId"),
            @ValidateFiled(index = 0, notNull = true, filedName = "module"),
            @ValidateFiled(index = 1, notNull = true),
            @ValidateFiled(index = 2, notNull = true),
    })
    public BaseResult selectModuleProductList(Product product, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Product> productList = productService.selectModuleProductList(product);
        PageInfo<Product> pageInfo = new PageInfo<>(productList);
        return BaseResult.ok(pageInfo);
    }


    /**
     * showdoc
     *
     * @param id 必选 int ID
     * @return {"status":200,"msg":"SUCCESS","data":{"total":1,"list":[{"id":2,"name":"篮球","price":100.0,"integral":0,"stock":100,"desp":"圆圆的足球","module":"活动专区","categoryId":1,"type":"0","isShelf":0,"createTime":"2020-04-03T12:14:47.000+0000","supplierId":8,"payCategory":1,"version":0,"limitNumber":0,"isLimit":0,"priority":1,"deliveryMethod":"商家配送","coverImgUrl":"http://demo.com","carouselImgUrl":"http:demo1.com"}],"pageNum":10,"pageSize":0,"size":1,"startRow":1,"endRow":1,"pages":0,"prePage":0,"nextPage":0,"isFirstPage":false,"isLastPage":true,"hasPreviousPage":true,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[],"navigateFirstPage":0,"navigateLastPage":0}}
     * @catalog 商城/商品
     * @title 由主键查询产品
     * @description 由主键查询产品
     * @url /mall/product/selectProductById
     */
    @RequestMapping("/selectProductById")
    @ValidateGroup(fileds = {
            @ValidateFiled(index = 0, notNull = true),
    })
    public BaseResult selectProductById(Integer id) {
        Product product = productService.selectProductAndChangeViewCount(id);
        return BaseResult.ok(product);
    }

    /**
     * showdoc
     *
     * @param pageNum  必选 string 页码（0开始
     * @param pageSize 必选 int 每页数量
     * @param name     必选 string 商品名称
     * @return {"status":200,"msg":"SUCCESS","data":{"total":1,"list":[{"id":2,"name":"篮球","price":100.0,"integral":0,"stock":100,"desp":"圆圆的足球","module":"活动专区","categoryId":1,"type":"0","isShelf":0,"createTime":"2020-04-03T12:14:47.000+0000","supplierId":8,"payCategory":1,"version":0,"limitNumber":0,"isLimit":0,"priority":1,"deliveryMethod":"商家配送","coverImgUrl":"http://demo.com","carouselImgUrl":"http:demo1.com"}],"pageNum":10,"pageSize":0,"size":1,"startRow":1,"endRow":1,"pages":0,"prePage":0,"nextPage":0,"isFirstPage":false,"isLastPage":true,"hasPreviousPage":true,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[],"navigateFirstPage":0,"navigateLastPage":0}}
     * @catalog 商城/商品
     * @title 由名称查询商品分页
     * @description 由名称查询商品分页
     * @url /mall/product/selectProductByName
     */
    @RequestMapping("/selectProductByName")
    @ValidateGroup(fileds = {
            @ValidateFiled(index = 0, notNull = true),
            @ValidateFiled(index = 1, notNull = true),
            @ValidateFiled(index = 2, notNull = true),
    })
    public BaseResult selectProductByName(String name, Integer pageNum, Integer pageSize, Integer orderType, String sequence) {
        PageHelper.startPage(pageNum, pageSize);
        List<Product> productList = productService.selectProductByName(name, orderType, sequence);
        PageInfo<Product> pageInfo = new PageInfo<>(productList);
        return BaseResult.ok(pageInfo);
    }

}
